import request from '@/utils/request'

export async function createMySheet(data) {
  return request({
    url: '/v1/datalib/personal/sheet/',
    method: 'post',
    data,
  })
}

// 查询个人指标
export function getPersonalIndexes(
  user = 2,
  variety = null,
  page = 1,
  page_size = 30
) {
  return request({
    url: '/v1/datalib/personal/indexes/',
    method: 'get',
    params: { user, variety, page, page_size },
  })
}

// 为表添加一个指标
export function addSheetColumn(data){
  return request({
    url: '/v1/datalib/personal/sheet/column/',
    method: 'post',
    data,
  })
}

// 删除表中一个指标
export function delSheetColumn(data){
  return request({
    url: '/v1/datalib/personal/sheet/column/',
    method: 'delete',
    data,
  })
}

// 获取表的详细指标
export function getSheetColumns(sheetId){
  return request({
    url: '/v1/datalib/personal/sheet/column/',
    params: { sheet: sheetId },
    method: 'get',
  })
}

// 指定列提取表的数据
export function extraColumnsData(indexes, excel_name){
  return request({
    url: '/v1/datalib/personal/sheet/columns/data/',
    method: 'post',
    data: { indexes, excel_name },
  })
}

// 保存绘制的图形
export function saveChartOption(data){
  return request({
    url: '/v1/datalib/personal/chart/',
    method: 'post',
    data,
  })
}

// 修改图形配置
export function modifyChartOption(data){
  return request({
    url: '/v1/datalib/personal/chart/',
    method: 'put',
    data,
  })
}

// 删除图形
export function delChart(cid){
  return request({
    url: '/v1/datalib/personal/chart/',
    method: 'delete',
    params: { cid },
  })
}

// 删除数据表
export async function delSheet(sheet_id){
  return request({
    url: '/v1/datalib/personal/sheet/',
    method: 'delete',
    data: { sheet_id },
  })
}

// 查询图表分组名称
export const getDatalibGroups = (params) => {
  return request({
    url: '/v1/datalib/group/',
    method: 'get',
    params,
  })
}

// 新建图表分组名称
export const saveDatalibGroup = (data) => {
  return request({
    url: '/v1/datalib/group/',
    method: 'post',
    data,
  })
}

// 修改图形的归档
export const modifyChartGroup = (data) => {
  return request({
    url: '/v1/datalib/variety/chartGroup/',
    method: 'post',
    data,
  })
}

// 修改表的归档
export const modifySheetGroup = (data) => {
  return request({
    url: '/v1/datalib/variety/sheetGroup/',
    method: 'post',
    data,
  })
}

// 删除归档组
export const deleteDatalibGroup = (data) => {
  return request({
    url: '/v1/datalib/group/',
    method: 'delete',
    data,
  })
}

// 请求我的指标库分组
export const getMyDatalibGroup = (ven, gid) => {
  return request({
    url: '/v1/datalib/personal/dbIndexGroup/',
    method: 'get',
    params: { ven, gid },
  })
}

// 获取组下的指标列表
export const getMyGroupIndex = async (gid) => {
  return request({
    url: '/v1/datalib/personal/dbGroupIndexes/',
    method: 'get',
    params: { gid },
  })
}
export const deleteMyGroupIndex = async (row_id) => {
  return request({
    url: '/v1/datalib/personal/dbGroupIndexes/',
    method: 'delete',
    params: { row_id },
  })
}
